/*
创建缓存
 */
buf = new Buffer([10, 20, 30, 40, 50]);
buf = new Buffer("buffer", "utf-8");
buf = new Buffer(1000);//长度为10的缓存区

/*
写入缓存
 */
len = buf.write("www.runoob.com");

/*
读取数据
 */
console.log(buf.toString('utf8'));
console.log(buf.toString('utf8', 1, 3));

/*
转换JSON
 */
console.log(buf.toJSON());

/*
合并
 */
var buf1 = new Buffer("姓");
var buf2 = new Buffer("黄");
buf = Buffer.concat([buf1, buf2]);
console.log(buf.toString());

/*
比较
 */
var buffer1 = new Buffer('CD');
var buffer2 = new Buffer('ABCD');
var result = buffer1.compare(buffer2);
console.log("result " + result);
if (result < 0) {
    console.log(buffer1 + " 在 " + buffer2 + "之前");
} else if (result === 0) {
    console.log(buffer1 + " 与 " + buffer2 + "相同");
} else {
    console.log(buffer1 + " 在 " + buffer2 + "之后");
}